package logic

import (
	"context"
	"shenzhou-b/rpc/model/mysql"

	"shenzhou-b/rpc/car"
	"shenzhou-b/rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsListLogic {
	return &GoodsListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsListLogic) GoodsList(in *car.GoodsListRequest) (*car.GoodsListResponse, error) {
	// todo: add your logic here and delete this line

	g := mysql.Goods{}
	list, err := g.GoodsList(in.Status)
	if err != nil {
		return nil, err
	}
	var List []*car.GoodsItem
	for _, goods := range list {
		List = append(List, &car.GoodsItem{
			GoodsId:     int64(goods.ID),
			GoodsName:   goods.GoodsName,
			GoodsCover:  goods.GoodsCover,
			GoodsPrice:  float32(goods.GoodsPrice),
			GoodsStock:  goods.GoodsStock,
			GoodsStatus: goods.GoodsStatus,
		})
	}

	return &car.GoodsListResponse{GoodsItem: List}, nil
}
